﻿using System.Drawing;

namespace PlusPlusPaint.Layers.VisualObjects
{
    /// <summary>
    /// Represents a rectangle on the screen only the edges of which are
    /// visible.  The dimensions of the rectangle will be equal to the
    /// dimensions of the containing layer.
    /// </summary>
    class EmptyRectangle : DynamicallyGeneratedVisualObject
    {
        #region properties
        protected override string ObjectTypeName
        {
            get
            {
                return "EmptyRectangle";
            }
        }
        #endregion
        
        #region constructors
        public EmptyRectangle()
        {

        }

        public EmptyRectangle(Point begin, Point end)
        {
            SetBoxAround(begin, end);
        }
        #endregion

        #region overrides
        public override bool PositionIsInHitbox(Point p)
        {
            Rectangle rect = this.ClientRectangle; // This is by-value!
            rect.Inflate(2 * MaximumDistanceToRecogniseOnClick, 2 * MaximumDistanceToRecogniseOnClick);
            if (!FilledRectangle.IsInRectangleBoundedBy(rect, p))
                return false;
            rect.Inflate(-4 * MaximumDistanceToRecogniseOnClick, -4 * MaximumDistanceToRecogniseOnClick);
            return !FilledRectangle.IsInRectangleBoundedBy(rect, p);
        }

        public override IVisualObject Clone()
        {
            EmptyEllipse copy = new EmptyEllipse(this.Location, this.Location + this.Size);
            copy.Colour = Colour;
            return copy;
        }

        public override void BurnOn(Image im)
        {
            using (Pen p = new Pen(this.Colour, this.BrushSize))
            {
                Graphics.FromImage(im).DrawRectangle(p, this.ClientRectangle);
            }
        }
        #endregion
    }
}
